import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:wowhy/service_locator.dart';
import 'package:wowhy/services/navigate_service.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(
  AdminUserItemState state,
  Dispatch dispatch,
  ViewService viewService,
) {
  return Card(
    elevation: 15.0,
    child: Column(
      children: <Widget>[
        ListTile(
          title: Text('${state.model.nickName}'),
          subtitle: Text('${state.model.userName}'),
          onTap: () {
            dispatch(AdminUserItemActionCreator.onDetail());
          },
          trailing: IconButton(
            icon: Icon(Icons.more_horiz),
            onPressed: () {
              showModalBottomSheet(
                  context: viewService.context,
                  builder: (BuildContext context) {
                    return SafeArea(
                      child: Column(
                        mainAxisSize: MainAxisSize.min, // 设置最小的弹出
                        children:
                            buildExtendActions(state, dispatch, viewService),
                      ),
                    );
                  });
            },
          ),
        ),
      ],
    ),
  );
}

List<Widget> buildExtendActions(
  AdminUserItemState state,
  Dispatch dispatch,
  ViewService viewService,
) {
  return [
    new ListTile(
      leading: new Icon(Icons.lock_outline),
      title: new Text(
        "编辑",
      ),
      onTap: () async {
        getIt<NavigateService>().pop();
        dispatch(AdminUserItemActionCreator.onEdit());
      },
    ),
    new ListTile(
      leading: new Icon(
        Icons.delete,
        color: Colors.redAccent,
      ),
      title: new Text(
        "删除",
        style: TextStyle(
          color: Colors.redAccent,
        ),
      ),
      onTap: () async {
        getIt<NavigateService>().pop();
        dispatch(AdminUserItemActionCreator.onRemove());
      },
    ),
  ];
}
